package social

import (
	"server/social/handle"
	"server/social/model"

	"github.com/hwcer/cosgo"
	"github.com/hwcer/cosgo/utils"
	"github.com/hwcer/cosmo"
	"github.com/hwcer/yyds/options"
)

var Graph = model.Graph

//var Likes = model.Likes

var m = &Module{}

var _ = handle.Register

func New() *Module {
	return m
}

// SetEmbed 设置成嵌入模式，不需要额外配置数据
func SetEmbed(mongo *cosmo.DB) {
	model.SetEmbed(mongo)
}

type Module struct {
}

func (this *Module) Id() string {
	return options.ServiceTypeSocial
}

func (this *Module) Init() (err error) {
	if model.Embed {
		return //内置模式
	}
	if err = options.Initialize(); err != nil {
		return
	}
	if err = cosgo.Config.UnmarshalKey(options.ServiceTypeSocial, &model.Options); err != nil {
		return
	}

	return utils.Assert(model.Start)
}
func (this *Module) Start() (err error) {
	return nil
}

func (this *Module) Close() (err error) {
	return nil
}
